package com.sqstudio.util
{
	/**
	 *字符串转码(Unicode)
	 * @author Nestor
	 * 
	 */	
	public class CharacterEncode
	{
		public function CharacterEncode()
		{
		}
		
		/**
		 * 把字符串转换成16进制的Unicode编码
		 * @param str
		 * @param separateStr
		 * @return 
		 * 
		 */		
		public static function toUnicode(str:String, separateStr:String="-"):String {
			var temp:String = "";
			for(var i:int=0; i<str.length; i++) {
				if(temp.length > 1) {
					temp += separateStr + str.charCodeAt(i).toString(16);
				}else {
					temp = String(str.charCodeAt(i).toString(16));
				}
			}
			return temp;
		}
		
		/**
		 * 将Unicode字节码转换成字符串 
		 * @param str  \uea32\ua2ee		
		 * @return 
		 */		
		public static function UnicodeToStr(str:String):String{
			var tempString:String = str.substring(2,str.length);
			var strArr:Array = tempString.split("\\u");
			var rtStr:String = "";
			for(var i:int = 0;i<strArr.length;i++){
				var num:Number = parseInt(strArr[i],16);
				rtStr += String.fromCharCode(num);
			}
			return rtStr;
		}
	}
}